package com.losdun.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.losdun.common.utils.DateUtils;
import com.losdun.product.domain.Attribute;
import com.losdun.product.domain.vo.TreeSelectVo;
import com.losdun.product.mapper.AttributeMapper;
import com.losdun.product.service.IAttributeService;
import com.losdun.product.utils.TreeSelectBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 产品属性Service业务层处理
 * 
 * @author sword.ye
 * @date 2025-02-27
 */
@Service
public class AttributeServiceImpl implements IAttributeService
{
    @Autowired
    private AttributeMapper attributeMapper;

    /**
     * 查询产品属性
     * 
     * @param id 产品属性主键
     * @return 产品属性
     */
    @Override
    public Attribute selectAttributeById(Long id)
    {
        return attributeMapper.selectAttributeById(id);
    }

    /**
     * 查询产品属性列表
     * 
     * @param attribute 产品属性
     * @return 产品属性
     */
    @Override
    public List<Attribute> selectAttributeList(Attribute attribute)
    {
        return attributeMapper.selectAttributeList(attribute);
    }

    /**
     * 新增产品属性
     * 
     * @param attribute 产品属性
     * @return 结果
     */
    @Override
    public int insertAttribute(Attribute attribute)
    {
        attribute.setCreateTime(DateUtils.getNowDate());
        return attributeMapper.insertAttribute(attribute);
    }

    /**
     * 修改产品属性
     * 
     * @param attribute 产品属性
     * @return 结果
     */
    @Override
    public int updateAttribute(Attribute attribute)
    {
        attribute.setUpdateTime(DateUtils.getNowDate());
        return attributeMapper.updateAttribute(attribute);
    }

    /**
     * 批量删除产品属性
     * 
     * @param ids 需要删除的产品属性主键
     * @return 结果
     */
    @Override
    public int deleteAttributeByIds(Long[] ids)
    {
        return attributeMapper.deleteAttributeByIds(ids);
    }

    /**
     * 删除产品属性信息
     * 
     * @param id 产品属性主键
     * @return 结果
     */
    @Override
    public int deleteAttributeById(Long id)
    {
        return attributeMapper.deleteAttributeById(id);
    }

    @Override
    public List<TreeSelectVo> selectAttributeTree(Attribute attribute) {
        List<Attribute> attrList = attributeMapper.selectAttributeList(attribute);
        return new TreeSelectBuilder<Attribute>().buildTree(attrList);
    }
}
